package stc.skymobi.transport.protocol.pf;

import stc.skymobi.bean.pf.annotation.PFField;

//PF header
//0                             
//0 1 2 3 4 5 6 7 
//+-+-+-+-+-+-+-+-+
//|    seqId(4)   |
//|               |
//|               |
//|               |
//+-+-+-+-+-+-+-+-+
//|   msgCode(4)  |
//|               |
//|               |
//|               |
//+-+-+-+-+-+-+-+-+
//|   result(1)   |
//+-+-+-+-+-+-+-+-+
//| msgbodylen(4) |
//|               |
//|               |
//|               |
//+-+-+-+-+-+-+-+-+
//|   msgbody(n)  |
//+-+-+-+-+-+-+-+-+

//字段名称    字段大小    取值范围    功能说明
//序列号
//(seqId)   4(byte) [0,2^32-1]  从0开始最大为4294967295的自增序列号
//消息编码
//(msgCode) 4(byte) [0,2^32]    具体每种消息的类型编号（奇数为请求，偶数为响应）
//消息结果
//(result)  1(byte) [0,255]     返回消息结果编号（错误码）
//消息长度
//(msgbodylen)  4(byte)   [0,2^32-1]   源功能模块编号
//协议数据域
//(msgbody)   n   n/a   唯一对应某个消息编码

/**
 * PF(用户档案服务)协议头
 * 
 * @author Shawn.Du
 */
public class PFHeader {
	public static final int PF_HEADER_LENGTH = 9;

	@PFField(index = 0)
	private int seqId;

	@PFField(index = 1)
	private int msgCode;

	@PFField(index = 2)
	private byte result;

	@PFField(index = 3)
	private int msgbodylen;

	public int getSeqId() {
		return seqId;
	}

	public int getMsgCode() {
		return msgCode;
	}

	public byte getResult() {
		return result;
	}

	public int getMsgbodylen() {
		return msgbodylen;
	}

	public void setSeqId(int seqId) {
		this.seqId = seqId;
	}

	public void setMsgCode(int msgCode) {
		if (msgCode <= 0) {
			throw new RuntimeException("invalid message code.");
		}
		this.msgCode = msgCode;
	}

	public void setResult(byte result) {
		this.result = result;
	}

	public void setMsgbodylen(int msgbodylen) {
		this.msgbodylen = msgbodylen;
	}

}
